{% extends 'base.html' %}
{% load static %}

{% block title %}我的关注 - Meet活动聚{% endblock %}

{% block content %}
<div class="container">
    <div class="row">
        <div class="col-12">
            <div class="card shadow">
                <div class="card-header bg-success text-white">
                    <h4 class="mb-0"><i class="bi bi-person-check"></i> 我的关注</h4>
                </div>
                <div class="card-body">
                    {% if following %}
                    <div class="list-group">
                        {% for follow in following %}
                        <div class="list-group-item">
                            <div class="d-flex justify-content-between align-items-center">
                                <div class="d-flex align-items-center">
                                    {% if follow.following.avatar %}
                                    <img src="{{ follow.following.avatar.url }}" class="rounded-circle me-3" width="50" height="50" alt="{{ follow.following.username }}">
                                    {% else %}
                                    <i class="bi bi-person-circle me-3" style="font-size: 2rem;"></i>
                                    {% endif %}
                                    <div>
                                        <h6 class="mb-1">{{ follow.following.nickname|default:follow.following.username }}</h6>
                                        <p class="mb-1 text-muted">{{ follow.following.signature|default:"这个人很懒，什么都没有写" }}</p>
                                        <small class="text-muted">关注于 {{ follow.created_at|date:"Y-m-d" }}</small>
                                    </div>
                                </div>
                                <div>
                                    <a href="{% url 'users:user_profile' follow.following.id %}" class="btn btn-sm btn-outline-primary me-1">
                                        <i class="bi bi-person"></i> 查看主页
                                    </a>
                                    <a href="{% url 'social:chat_main' %}" class="btn btn-sm btn-outline-success me-1">
                                        <i class="bi bi-envelope"></i> 发消息
                                    </a>
                                    <button class="btn btn-sm btn-outline-secondary btn-unfollow" data-user-id="{{ follow.following.id }}">
                                        <i class="bi bi-person-dash"></i> 取消关注
                                    </button>
                                </div>
                            </div>
                        </div>
                        {% endfor %}
                    </div>
                    {% else %}
                    <div class="text-center py-4">
                        <i class="bi bi-person-plus" style="font-size: 4rem; color: #6c757d;"></i>
                        <h5 class="mt-3">暂无关注</h5>
                        <p class="text-muted">您还没有关注任何人，快去发现有趣的人吧！</p>
                        <a href="{% url 'activities:activity_list' %}" class="btn btn-primary">
                            <i class="bi bi-search"></i> 去发现活动
                        </a>
                    </div>
                    {% endif %}
                </div>
            </div>
        </div>
    </div>
</div>
{% endblock %}

{% block extra_js %}
<script>
$(document).ready(function() {
    // 取消关注功能
    $('.btn-unfollow').click(function() {
        var userId = $(this).data('user-id');
        var $btn = $(this);
        var $listItem = $btn.closest('.list-group-item');
        
        if (confirm('确定要取消关注吗？')) {
            $.ajax({
                url: '/social/unfollow/' + userId + '/',
                type: 'POST',
                data: {
                    csrfmiddlewaretoken: '{{ csrf_token }}'
                },
                success: function(response) {
                    if (response.success) {
                        $listItem.fadeOut(300, function() {
                            $(this).remove();
                        });
                    } else {
                        alert(response.message);
                    }
                },
                error: function() {
                    alert('取消关注失败，请重试');
                }
            });
        }
    });
});
</script>
{% endblock %}